
#define Pump_Variable
#include "userDef.h"

//#ifdef PUMP
Pump_typeDef Pump;
PumpDataTypeDef Pump_1;


void Pump_Act( void )
{
    static U8 Flag = 0;

    if ( b_power.run == ON && ( e_mode.run == MODECOOL || e_mode.run == MODEDRY ) && ( f_RoomUnitOn == ON ) && ( ErrFlagQT == 0 ) && ( ErrFlag == 0 ) ) // 制冷/除湿/自动制冷模式下，压缩机启动，水泵同时启动运行�?
    {
        Pump_1.OnOrOff = 1;
        Flag    = 1;
    }
    else if (( Pump_1.Min_1_CorrelationCoolDryFlag == 1 )&& (b_power.run == ON)) //如果1min 内，制冷/除湿开机水泵继续运行,如果再次关机，则回到1分钟之后关闭的情况
    {
        Pump_1.OnOrOff = 1;
        Flag    = 1;
    }
    else if ( ( f_RoomUnitOn == OFF ) && ( Flag == 1 ) ) // 压缩机停机后 延时 1分钟关闭水泵
    {
        Flag    = 0;
        Pump_1.Min_1_Falg = 1;
        Pump_1.OnOrOff = 1;

		if ( Pump_1.Min_1_CorrelationCoolDryFlag == 1 )Pump_1.Min_1_CorrelationCoolDryFlag =0;
    }
    else if ( Pump_1.Min_1_Falg == 1 )
    {
        Pump_1.OnOrOff = 1;
    }
    else if ( f_OutErr_U9 == 1 ) //防结冻保�?
    {
        Pump_1.OnOrOff = 1;
    }
    else if ( f_OutErr_H3 == TRUE || f_waterErr == TRUE || Pump_1.Min_1_CorrelationWaterFullFlag == 1 ) // 制冷或除湿模式开机下，连�?s 检测到水满信号时，进入保护状态，水泵强制启动运行
    {
        Pump_1.OnOrOff = 1;
    }
    else if ( ( Pump_1.Min_1_CorrelationWaterFullFlag == 0 ) && ( b_power.run == OFF ) )
    {
        if ( f_waterErr == FALSE )
        {
            Pump_1.OnOrOff = 0;
        }
    }

    /*
        if ( f_OutErr_H3 == TRUE || f_waterErr == TRUE )
        {
            f_ctrl_pump = ON;
            Pump.delay_s = 60;
        }
        else 
        {
            if ( b_power.run == ON && ( e_mode.run == MODECOOL || e_mode.run == MODEDRY ) && f_RoomUnitOn == ON && ErrFlagQT == 0 && ErrFlag == 0 )
            {
                f_ctrl_pump = ON;
                Pump.delay_s = 60;
            }
            else 
            {
                if ( Pump.delay_s == 0 )
                {
                    f_ctrl_pump = OFF;
                }
            }
        }
      */
}


void Pump_timer_1s( void ) /* called in SysTime.c per 1s，quicktest per 200ms */
{
    /*
        if ( Pump.delay_s > 0 )
        {
            Pump.delay_s--;
        }
    */
    Water_on_check();
}


void Water_on_check( void ) // per 200ms
{
#ifdef MACHINE_TYPE_TJ
    if ( Pump_1.Min_1_Falg == 1 ) // 1分内出现水满
    {
        if ( IO_WATER_CHECK == OFF )
        {
            if ( Pump_1.WaterErrCount < 8 ) // 8S
            {
                Pump_1.WaterErrCount++;
            }
            else 
            {
                f_waterErr = TRUE;
            }
        }
        else 
        {
            Pump_1.WaterErrCount = 0;
            f_waterErr = FALSE;         //水泵报警消失
        }
    }
    else 
    {
        if ( b_power.run == ON && ( e_mode.run == MODECOOL || e_mode.run == MODEDRY ) && IO_WATER_CHECK == OFF ) // 常闭型，断开水满，低电平�?
        {
            if ( Pump_1.WaterErrCount < 8 ) // 8S
            {
                Pump_1.WaterErrCount++;
            }
            else 
            {
                f_waterErr = TRUE;
            }
        }
        else 
        {
            if ( IO_WATER_CHECK == OFF )
            {
                if ( Pump_1.WaterErrCount < 8 ) // 8S
                {
                    Pump_1.WaterErrCount++;
                }
                else 
                {
                    f_waterErr = TRUE;
                }
            }
            else 
            {
                Pump_1.WaterErrCount = 0;
                f_waterErr = FALSE;     //水泵报警消失
            }

            if ( ( b_power.run == OFF ) && ( Pump_1.Min_1_CorrelationWaterFullFlag == 1 ) ) // 
            {
                if ( f_waterErr == FALSE )
                {
                    Pump_1.Min_1_CorrelationWaterFullFlag = 0;
                    Pump_1.OnOrOff = 0;
                }
            }
        }
    }

#endif // MACHINE_TYPE_TJ

#ifdef MACHINE_TYPE_FG
    if ( b_power.run == ON && ( e_mode.run == MODECOOL || e_mode.run == MODEDRY ) && IO_WATER_CHECK == ON ) // 常闭型，断开水满，高电平�?
    {
        if ( Pump.water_on_s < 8 )
        {
            Pump.water_on_s++;
        }
        else 
        {
            f_waterErr = TRUE;
        }
    }
    else 
    {
        Pump.water_on_s = 0;
        if ( b_power.set == OFF )
        {
            f_waterErr = FALSE;         // 关机清水满保护故障；
        }
    }

#endif // MACHINE_TYPE_FG

#ifdef MACHINE_TYPE_ZD
    if ( b_power.run == ON && ( e_mode.run == MODECOOL || e_mode.run == MODEDRY ) && IO_WATER_CHECK == OFF ) // 常开型，闭合水满，低电平�?
    {
        if ( Pump.water_on_s < 8 )
        {
            Pump.water_on_s++;
        }
        else 
        {
            f_waterErr = TRUE;
        }
    }
    else 
    {
        Pump.water_on_s = 0;
        if ( b_power.set == OFF )
        {
            f_waterErr = FALSE;         // 关机清水满保护故障；
        }
    }

#endif // MACHINE_TYPE_ZD
}


//#endif

